Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add test that generated json from autoyast xml is valid #1946

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

jreidinger
Copy link
Contributor

@jreidinger jreidinger commented Jan 24, 2025

Problem

autoinst.xml profile conversion can lead to non valid profile.json

#1960
#1907
#1903

Solution

Add ci test to validate cloned autoyast profile. Fix issue with localization. Fix other autoyast conversion related issues.

Note: sadly I need to add python3-jsonschema to install as rubygem-json-schema does not support anything newer then draft5 json schema and we use newer.

Testing

  • Added a new unit test

Output

before pretty generate

{"localization":{"timezone":"America/New_York"},"product":{"id":"SLES"},"root":{"password":"$6$sxZ921ci.szwhCIw$9lrLQTtanJcpPeJkqv9pU0LsKQLO3RcPhBPBDMfc1uGUDCfgiyEyGPNr/ZKXAgqZsL61DANvr4uAYYDkif/Ma0","hashedPassword":true},"software":{"patterns":["apparmor","base","basic_desktop","enhanced_base","minimal_base","x11","x11_yast","yast2_basis"]},"legacyAutoyastStorage":[{"device":"/dev/system","enable_snapshots":true,"partitions":[{"create":true,"filesystem":"xfs","format":false,"lv_name":"home","mount":"/home","mountby":"device","pool":false,"resize":false,"size":"5792333824","stripes":1,"stripesize":0},{"create":true,"create_subvolumes":true,"filesystem":"btrfs","format":false,"lv_name":"root","mount":"/","mountby":"device","pool":false,"quotas":true,"resize":false,"size":"13522436096","stripes":1,"stripesize":0,"subvolumes":[{"copy_on_write":false,"path":"var"},{"copy_on_write":true,"path":"usr/local"},{"copy_on_write":true,"path":"tmp"},{"copy_on_write":true,"path":"srv"},{"copy_on_write":true,"path":"root"},{"copy_on_write":true,"path":"opt"},{"copy_on_write":true,"path":"boot/grub2/x86_64-efi"},{"copy_on_write":true,"path":"boot/grub2/i386-pc"}],"subvolumes_prefix":"@"},{"create":true,"filesystem":"swap","format":false,"lv_name":"swap","mount":"swap","mountby":"device","pool":false,"resize":false,"size":"2147483648","stripes":1,"stripesize":0}],"pesize":"4194304","type":"CT_LVM"},{"device":"/dev/sda","disklabel":"gpt","partitions":[{"create":true,"format":false,"partition_id":263,"partition_nr":1,"resize":false,"size":"8388608"},{"create":true,"format":false,"lvm_group":"system","partition_id":142,"partition_nr":2,"resize":false,"size":"21465382400"}],"type":"CT_DISK","use":"all"}],"user":{"userName":"tux","fullName":"tux","password":"$6$epM6.b193j7ZvUaw$/oMPS9pQR9X9i1MAJag20ZFy0XSI4985uVQDGLugwoCbDJVoXKCWLMFM.WncHr/bpkjecwb.LLaJeheYatq8f.","hashedPassword":true}}

after pretty generate

{
  "localization": {
    "timezone": "America/New_York"
  },
  "product": {
    "id": "SLES"
  },
  "root": {
    "password": "$6$sxZ921ci.szwhCIw$9lrLQTtanJcpPeJkqv9pU0LsKQLO3RcPhBPBDMfc1uGUDCfgiyEyGPNr/ZKXAgqZsL61DANvr4uAYYDkif/Ma0",
    "hashedPassword": true
  },
  "software": {
    "patterns": [
      "apparmor",
      "base",
      "basic_desktop",
      "enhanced_base",
      "minimal_base",
      "x11",
      "x11_yast",
      "yast2_basis"
    ]
  },
  "legacyAutoyastStorage": [
    {
      "device": "/dev/system",
      "enable_snapshots": true,
      "partitions": [
        {
          "create": true,
          "filesystem": "xfs",
          "format": false,
          "lv_name": "home",
          "mount": "/home",
          "mountby": "device",
          "pool": false,
          "resize": false,
          "size": "5792333824",
          "stripes": 1,
          "stripesize": 0
        },
        {
          "create": true,
          "create_subvolumes": true,
          "filesystem": "btrfs",
          "format": false,
          "lv_name": "root",
          "mount": "/",
          "mountby": "device",
          "pool": false,
          "quotas": true,
          "resize": false,
          "size": "13522436096",
          "stripes": 1,
          "stripesize": 0,
          "subvolumes": [
            {
              "copy_on_write": false,
              "path": "var"
            },
            {
              "copy_on_write": true,
              "path": "usr/local"
            },
            {
              "copy_on_write": true,
              "path": "tmp"
            },
            {
              "copy_on_write": true,
              "path": "srv"
            },
            {
              "copy_on_write": true,
              "path": "root"
            },
            {
              "copy_on_write": true,
              "path": "opt"
            },
            {
              "copy_on_write": true,
              "path": "boot/grub2/x86_64-efi"
            },
            {
              "copy_on_write": true,
              "path": "boot/grub2/i386-pc"
            }
          ],
          "subvolumes_prefix": "@"
        },
        {
          "create": true,
          "filesystem": "swap",
          "format": false,
          "lv_name": "swap",
          "mount": "swap",
          "mountby": "device",
          "pool": false,
          "resize": false,
          "size": "2147483648",
          "stripes": 1,
          "stripesize": 0
        }
      ],
      "pesize": "4194304",
      "type": "CT_LVM"
    },
    {
      "device": "/dev/sda",
      "disklabel": "gpt",
      "partitions": [
        {
          "create": true,
          "format": false,
          "partition_id": 263,
          "partition_nr": 1,
          "resize": false,
          "size": "8388608"
        },
        {
          "create": true,
          "format": false,
          "lvm_group": "system",
          "partition_id": 142,
          "partition_nr": 2,
          "resize": false,
          "size": "21465382400"
        }
      ],
      "type": "CT_DISK",
      "use": "all"
    }
  ],
  "user": {
    "userName": "tux",
    "fullName": "tux",
    "password": "$6$epM6.b193j7ZvUaw$/oMPS9pQR9X9i1MAJag20ZFy0XSI4985uVQDGLugwoCbDJVoXKCWLMFM.WncHr/bpkjecwb.LLaJeheYatq8f.",
    "hashedPassword": true
  }
}

Copy link
Contributor

@imobachgs imobachgs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor comments. Otherwise, LGTM.

@@ -100,10 +101,10 @@ def read_init_scripts
# @param section [Hash] AutoYaST script section
def read_script(section)
script = {
"name" => section["file_name"]
"name" => section["filename"] || "annonymous#{@anonymous_counter += 1}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: it should be anonymous but, to be honest, I do not like that prefix that much. I would prefer script-, or unnamed- or something else.

context "for cloned profile" do
let(:profile_name) { "cloned.xml" }

it "generate json according to schema" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it "generate json according to schema" do
it "generate JSON according to schema" do

@@ -177,4 +178,29 @@
subject.to_agama(workdir)
end
end

context "for cloned profile" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is just an AutoYaST profile, right? No matter whether it is cloned or written from scratch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants